﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

using SpectrEngine.Framework;

using CellWarzGame.Actors;


namespace CellWarzGame.Actors
{
    static class CellFactory
    {
        public static Game game{get;set;}
        private static Random rand = new Random();

        public static void CreateCell(Cell.Side side, Cell.Controler controler, Cell.CellType cellType, Vector2 position)
        {
            Debug.Assert(game != null, "Game is null");
            
            Cell c = new Cell(game, side, controler, position, cellType);
            c.toClose = (float)rand.NextDouble() * 200 + 100;
            c.toFar = (float)rand.NextDouble() * 300 + 500;
        }

        public static void CreateCells(int count, Cell.Side side, Cell.Controler controler, Cell.CellType cellType, Rectangle area)
        {
            for (int i = 0; i < count; i++)
            {
                CreateCell(side, controler, cellType, new Vector2(area.X + area.Width * (float)rand.NextDouble(), area.Y + area.Height * (float)rand.NextDouble()));
            }
        }

        public static void CreateCells(int count, Cell.Side side, Cell.Controler controler, Rectangle area)
        {
            Cell.CellType cellType;
            for (int i = 0; i < count; i++)
            {
                if (rand.NextDouble()  < 0.33)
                    cellType = Cell.CellType.Monk;
                else if (rand.NextDouble() < 0.66)
                    cellType = Cell.CellType.Punk;
                else
                    cellType = Cell.CellType.Skunk;

                CreateCell(side, controler, cellType, new Vector2(area.X + area.Width * (float)rand.NextDouble(), area.Y + area.Height * (float)rand.NextDouble()));
            }
        }
    }
}
